<?php
include_once('clogin.inc.php');
include_once('admin_head.php');
/*include_once('../fckeditor/fckeditor.php');		//引用FCKeditor.php这个文件
$oFCKeditor=new FCKeditor('content');             //创建FCKeditor对象的实例
$oFCKeditor->BasePath='FCKeditor/';               //FCKeditor所在的位置，这里它的位置就是'FCKeditor/';
$oFCkeditor->ToolbarSet='Default';                //工具按钮设置
$oFCKeditor->Width='100%';                        //设置它的宽度
$oFCKeditor->Height='300px';                      //设置它的高度
$oFCkeditor->Create;
*/
?>

<? 
//set_magic_quotes_runtime(0);
//echo get_magic_quotes_runtime();
$uid = $_SESSION["uid"];
$model_name ='资料';
if ($_POST['action'] == 'edit'){
	$id = intval($_POST['id']);
	$title = $_POST['title'];
	$content = $_POST['content'];
	$cid = $_POST['cid'];
	$copyform = $_POST['copyform'];
	$info = 1;
	$update_time = time();
	$uid = $_SESSION["uid"];
	$auto_keywords = $_POST["auto_keywords"];
	$keywords = $_POST["keywords"];
	
	if($auto_keywords){
		//
		//echo get_use_time();
		$keywords = get_keywords(strip_tags($title.$content));
		
		//pecho($keywords);
		//echo get_use_time();
		//$keywords = get_keywords2($content);
		//pecho($keywords);
		//
		//exit();
	}
/*	echo $id;
	echo $sitename;
	echo $url;
	echo $info;
	echo $displayid;*/

	if (empty($id)) {
		//$sql = "INSERT INTO {$tablepre}note (cid, title, content, uid, update_time,keywords) 
		//		VALUES($cid, '$title', '".($content)."', '$uid', $update_time,'$keywords')";
		$edit = '添加';		
		
		$dbarr['cid'] = $cid;
		$dbarr['copyform'] = $copyform;
		$dbarr['uid'] = $uid;
		$dbarr['title'] = $title;
		$dbarr['content'] = $content;
		$dbarr['update_time'] = $update_time;
		$dbarr['create_time'] = $update_time;
		$dbarr['keywords'] = $keywords;
		
		
		$sql = make_insert_sql("{$tablepre}note",$dbarr);
		
		
	}else{
		$dbarr['cid'] = $cid;
		$dbarr['copyform'] = $copyform;
		$dbarr['uid'] = $uid;
		$dbarr['title'] = $title;
		$dbarr['content'] = $content;
		$dbarr['update_time'] = $update_time;
		$dbarr['keywords'] = $keywords;
		
		$where['id'] = $id;
		$sql = make_update_sql("{$tablepre}note",$dbarr,$where);
		
		//echo htmlentities($content);
		//echo '<br><br><br>';
		//echo htmlentities($sql);
//		echo '<br><br><br><br><br><br>';
//		echo $sql;
//		exit();
		//$sql = "UPDATE {$tablepre}note SET cid = '$cid', title = '$title', content = '".($content)."', uid = '$uid', update_time = '$update_time' WHERE id = $id LIMIT 1";
	
		$edit = '修改';	
	} 

	
	mysql_query($sql) or die(mysql_error()); 	

	if ( mysql_affected_rows() == 1 ) {
		if(mysql_insert_id()) $id = mysql_insert_id();
		if($edit == '添加'	)showmsg("{$model_name}{$edit}成功！",'成功',"?id=$id",'返回');
		
	}else{
		 showmsg("{$model_name}{$edit}失败或没有修改！",'失败',"return",'返回');
	}
	$_GET['id']=$_POST['id']=$id;
}
if ($_GET['id']) {
	$id = intval($_GET['id']);
	if ($_GET['action'] == 'del'){//删除
		$edit = '删除';	
		$sql = "DELETE FROM {$tablepre}note WHERE id = $id LIMIT 1";
		mysql_query($sql);
		showmsg("{$model_name}{$edit}成功！",'成功',"../frmView_right.php",'返回');
		exit();
		
	}
	$sql = "SELECT n.*, c.pid, c.name, c.component  FROM {$tablepre}note n LEFT JOIN {$tablepre}channel c on (n.cid = c.id) WHERE n.id= $id";
	$result=mysql_query($sql); 
	$enotes = mysql_fetch_array($result);
	if(!$enotes){
		showmsg("{$model_name}资料不存在",'错误',"../frmView_right.php",'返回');
	}
	
}
?>
<?php 

$cat_select = cat_list(0,$enotes['cid'],'cid');
?>
<div class="edit">
<div class="title"><?php 
if ($_GET['id']) {
	echo "编辑：<a href=\"../view_note.php?id={$enotes[id]}\"> $enotes[title]</a>  信息 [<a href=\"admin_note.php\">添加一个新的</a>]";
}else{
	echo "添加资料";	
}
?></div>
<form id="form1" name="form1" method="post" action="">

    <p>
    <input name="action" type="hidden" value="edit">
    <input name="id" type="hidden" value="<? echo $enotes['id'] ?>">
        
        <br>
        <label>标题：</label>
        <input name="title" type="text" id="title" value="<? echo $enotes['title'] ?>" size="70" style="width:80%" >
        </p>
    <p>
        <label>来源：</label>
        <input name="copyform" type="text" id="copyform" value="<? echo $enotes['copyform'] ?>" size="70" style="width:80%" />
        </p>
    <p>
        <label>
            分类：</label>
        <?php echo $cat_select ?>
        </p>
    <p><label>Tags:</label>
        <input name="keywords" type="text" id="keywords" value="<? echo $enotes['keywords'] ?>" size="70" style="width:70%" /></p>
    <p>
            <label style="margin-left:75px"><input name="auto_keywords" type="checkbox" value="1" <?php if(!$enotes['keywords']) echo 'checked="checked"'?> />
            自动提取</label>
        关键词
        <br>
        <label>内容：</label>
        
        
        <textarea name="content1"  id="content1" style="display:none" ><?php echo htmlentities($enotes['content'], ENT_COMPAT ,'utf-8') ?></textarea>
        
        
        <!--<INPUT id=content style="DISPLAY: none" type=hidden name="guan">
	<INPUT id=content___Config style="DISPLAY: none" type=hidden>
	<IFRAME id=content___Frame src="../FCKeditor/editor/fckeditor.html?InstanceName=guan&amp;Toolbar=Default" frameBorder=0 width=100% scrolling=no height=300>
	</IFRAME>-->
        
        <script type="text/javascript">
<!--
// Automatically calculates the editor base path based on the _samples directory.
// This is usefull only for these samples. A real application should use something like this:
// oFCKeditor.BasePath = '/fckeditor/' ;	// '/fckeditor/' is the default value.
//var sBasePath = document.location.pathname.substring(0,document.location.pathname.lastIndexOf('_samples')) ;

var oFCKeditor = new FCKeditor( 'content' ) ;
//oFCKeditor.BasePath	= sBasePath ;
oFCKeditor.Height	= 300 ;
oFCKeditor.toolbarSet = 'Default';
oFCKeditor.Value = document.getElementById('content1').value;
oFCKeditor.Create() ;
//-->
		  </script>
        <!--　<script type="text/javascript"> 　　CKEDITOR.replace( 'content1' ); 　　</script>         -->
    </p>
    <p>
        
        <input type="submit" name="Submit" value="保存修改">
        
          <input type="button" name="Submit2" value="取消返回" onClick="history.back()">
	</p>
</form>
<?php
if($_POST){
echo '保存成功:'.date('Y-m-d H:i:s');
}
?>

</div>

</body>
</html>